<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;
use app\index\model\System;
use app\index\model\BalanceLog;

class Index extends Base
{
    //我的分红
    public function index()
    {

        $sys=new System();
        $sysData=$sys->getSystem($this->uid);

        $award=Db::name("award_percent")->select();
        $strTime="";
        $strNum="";
        foreach($award as $k=>$v)
        {
            if($k==count($award)-1)
            {
                $strNum.="'".$v["percent"]."'";
                $strTime.="'".date("Y-m-d",$v["create_time"])."'";
            }else
            {
                $strNum.="'".$v["percent"]."',";
                $strTime.="'".date("y/m/d",$v["create_time"])."',";
            }
        }
        $this->assign("strNum",$strNum);
        $this->assign("strTime",$strTime);

        $this->assign("sysData",$sysData);
        return $this->fetch();
    }
    //佣金
    public function brokerage()
    {
        $sys=new System();
        $sysData=$sys->getSystem($this->uid);
        $this->assign("sysData",$sysData);
        return $this->fetch();
    }

    //上拉加载数据  分红记录
    public function getloglist()
    {
        $blog=new BalanceLog();
        $logList=$blog->getLogList($this->uid,1,0);
        if(!empty($logList))
        {
            return AjaxReturn(0,"",$logList);
        }else
        {
            return AjaxReturn(1,lang("empty_list"));
        }

    }
      //投资 记录
    public function get_invest_list()
    {
        $blog=new BalanceLog();
        $logList=$blog->getLogList($this->uid,2,9);
        if(!empty($logList))
        {
            return AjaxReturn(0,"",$logList);
        }else
        {
            return AjaxReturn(1,lang("empty_list"));
        }
    }
    //提现记录列表  收益
    public function get_withdraws()
    {
        $blog=new BalanceLog();
        $logList=$blog->getLogList($this->uid,1,4);
        if(!empty($logList))
        {
            return AjaxReturn(0,"",$logList);
        }else
        {
            return AjaxReturn(1,lang("empty_list"));
        }
    }
    //收益转筹 记录
    public function get_withdrawc()
    {
        $blog=new BalanceLog();
        $logList=$blog->getLogList($this->uid,2,6);
        if(!empty($logList))
        {
            return AjaxReturn(0,"",$logList);
        }else
        {
            return AjaxReturn(1,lang("empty_list"));
        }
    }

    //佣金记录列表
    public function get_brokerage()
    {
        $blog=new BalanceLog();
        $logList=$blog->getLogListU($this->uid,1,2);
        if(!empty($logList))
        {
            return AjaxReturn(0,"",$logList);
        }else
        {
            return AjaxReturn(1,lang("empty_list"));
        }
    }
    //公司介绍
    public function company()
    {
        return $this->fetch();
    }

    public function logout()
    {
        $uid = Session::set("uid",null);
        if(empty($uid)){
            $redirect = "/index/login";
            $this->redirect($redirect);
        }
    }
}
